﻿'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2008
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
'

' Adapted from:
' Rob Zelt
' http://www.robzelt.com/blog/CommentView,guid,b53a709e-cd21-460f-a33b-c7a8e02e8bd6.aspx#commentstart


Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports System.Collections.Generic
Imports System.Web
Imports System.Xml
Imports System.Security
Imports System.IO
Imports System.Globalization
Imports Microsoft.VisualBasic

Namespace DotNetNuke.Modules.IWebCF

    Public Class CoreHostFactory
        Inherits ServiceHostFactory
        Protected Overloads Overrides Function CreateServiceHost(ByVal serviceType As Type, ByVal baseAddresses As Uri()) As ServiceHost
            ' Define your own Address:
            ' Dim MyURI As New Uri("http://DotNetNuke.com/DesktopModules/IWebCF/CoreService.svc")

            ' Or just use the first one that is bound to the web server (baseAddresses(0))
            ' This is usually "localhost"
            ' Most webservers will have "localhost" plus additional domains like "DotNetNuke.com" and "www.DotNetNuke.com"

            Dim MyURI As Uri = baseAddresses(0)

            If DAL.WCF_Setting() <> "" Then
                MyURI = New Uri(DAL.WCF_Setting())
            End If

            Dim customServiceHost As New CustomHost(serviceType, MyURI)
            Return customServiceHost
        End Function
    End Class

    Public Class CustomHost
        Inherits ServiceHost
        Public Sub New(ByVal serviceType As Type, ByVal ParamArray baseAddresses As Uri())
            MyBase.New(serviceType, baseAddresses)
        End Sub
        Protected Overloads Overrides Sub ApplyConfiguration()
            MyBase.ApplyConfiguration()
        End Sub
    End Class

End Namespace